/**
 * https://leetcode-cn.com/problems/remove-duplicate-node-lcci/
 * 移除未排序的重复节点
 * @param head 
 */
const removeDuplicateNodes = (head: ListNode | null): ListNode | null => {
    // 边界判断
    if (head === null) return null

    // 存放出现过的节点
    const map: Record<number, boolean> = {}

    let root = head;
    while (head !== null && head.next !== null) {
        map[head.val] = true;

        if (map[head.next.val]) {
            // 存在map中, 说明是重复节点, 下次继续判断该head.next
            head.next = head.next.next;
        } else {
            // head.next放入map中
            map[head.next.val] = true;
            // head指向下一个
            head = head.next;
        }

    }

    return root;
};